<template>
  <div id="UpdateData">
    <main>
      <p>闲林街道后台管理页</p>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column type="index" label="#" align="center">
        </el-table-column>
        <el-table-column prop="community" label="社区" align="center">
        </el-table-column>
        <el-table-column label="编辑" align="center">
          <template slot-scope="scope">
            <el-button type="warning" size="small" @click="openEdit(scope.row)"
              >修改</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-dialog title="修改" :visible.sync="dialogVisible" width="30%">
        <el-form>
          <el-form-item label="开卡记录数">
            <el-input v-model="form.cardCount"></el-input>
          </el-form-item>
          <el-form-item label="累计优惠价格	">
            <el-input v-model="form.totalDiscount"></el-input>
          </el-form-item>
          <el-form-item label="0-3岁">
            <el-input v-model="form.children"></el-input>
          </el-form-item>
          <el-form-item label="少年4-16岁">
            <el-input v-model="form.juvenile"></el-input>
          </el-form-item>
          <el-form-item label="残疾">
            <el-input v-model="form.disable"></el-input>
          </el-form-item>
          <el-form-item label="60岁以上">
            <el-input v-model="form.elder"></el-input>
          </el-form-item>
          <el-form-item label="空巢老人">
            <el-input v-model="form.emptyNest"></el-input>
          </el-form-item>
          <el-form-item label="独居">
            <el-input v-model="form.liveAlong"></el-input>
          </el-form-item>
          <el-form-item label="党员">
            <el-input v-model="form.partMember"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="edit">确 定</el-button>
        </span>
      </el-dialog>
    </main>
  </div>
</template>

<script>
export default {
  name: "UpdateData",
  data() {
    return {
      tableData: [],
      dialogVisible: false,
      form: {},
    };
  },
  mounted() {
    this.getStaticList();
  },
  methods: {
    getStaticList() {
      this.$axios.post("/staticdata/getStaticData").then((res) => {
        if (res.data.code == 200) {
          this.tableData = res.data.item;
        }
      });
    },
    openEdit(row) {
      this.form = { ...row };
      this.dialogVisible = true;
    },
    edit() {
      const query = this.$qs.stringify(this.form);
      this.$axios.post("/staticdata/updStaticData", query).then((res) => {
        if (res.data.code == 200) {
          this.$message.success("修改成功");
          this.dialogVisible = false;
          this.getStaticList();
        } else {
          this.$message.error("修改失败");
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
#UpdateData {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background-image: url("../assets/bg11.png");
  background-repeat: no-repeat;
  background-size: 100% 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  > main {
    width: 600px;
    height: 600px;
    overflow-y: scroll;
    background-color: #fff;
    > p {
      width: 100%;
      font-size: 30px;
      font-weight: 600;
      margin-top: 10px;
      text-align: center;
    }
    /deep/ .el-dialog {
      .el-dialog__body {
        display: flex;
        justify-content: center;
        .el-form {
          width: 80%;
        }
        .el-form-item__label {
          width: 10em;
        }
        .el-input {
          width: 200px;
        }
      }
    }
  }
}
</style>